using MediatR;
using Zhaoxi.Zhihu.Core.AppUserAggregate.Event;
using Zhaoxi.Zhihu.Core.QuestionAggregate.Entites;
using Zhaoxi.Zhihu.SharedKerel.Repositoy;

namespace Zhaoxi.Zhihu.Core.QuestionAggregate.Handler;

internal class FollowQuestionAddedEventHandler(IRepository<Question> questions):INotificationHandler<FollowQuestionAddedEvent>
{

    public async Task Handle(FollowQuestionAddedEvent notification, CancellationToken cancellationToken)
    {
        var question = await questions.GetByIdAsync(notification.FollowQuestion.QuestionId, cancellationToken);
        
        if (question is null)return;
        question.FollowCount += 1;
        await questions.SaveChangesAsync(cancellationToken);
    }
}